# version code 761
# Please fill out this stencil and submit using the provided submission script.

from vec import Vec
from GF2 import one


## Problem 1
def vec_select(veclist, k): 
    return [v for v in veclist if(v[k] == 0)]
    '''
    >>> D = {'a','b','c'}
    >>> v1 = Vec(D, {'a': 1})
    >>> v2 = Vec(D, {'a': 0, 'b': 1})
    >>> v3 = Vec(D, {        'b': 2})
    >>> v4 = Vec(D, {'a': 10, 'b': 10})
    >>> vec_select([v1, v2, v3, v4], 'a') == [Vec(D,{'b': 1}), Vec(D,{'b': 2})]
    True
    '''
    
    
def vec_sum(veclist, D):
    if(len(veclist) == 0):
        return Vec(D,{})
    else:
        return sum(veclist)   

    '''
    >>> D = {'a','b','c'}
    >>> v1 = Vec(D, {'a': 1})
    >>> v2 = Vec(D, {'a': 0, 'b': 1})
    >>> v3 = Vec(D, {        'b': 2})
    >>> v4 = Vec(D, {'a': 10, 'b': 10})
    >>> vec_sum([v1, v2, v3, v4], D) == Vec(D, {'b': 13, 'a': 11})
    True
    '''
    

def vec_select_sum(veclist, k, D): 
    return vec_sum(vec_select(veclist,k),D)
    '''
    >>> D = {'a','b','c'}
    >>> v1 = Vec(D, {'a': 1})
    >>> v2 = Vec(D, {'a': 0, 'b': 1})
    >>> v3 = Vec(D, {        'b': 2})
    >>> v4 = Vec(D, {'a': 10, 'b': 10})
    >>> vec_select_sum([v1, v2, v3, v4], 'a', D) == Vec(D, {'b': 3})
    True
    '''
    



## Problem 2
def scale_vecs(vecdict):
    return [(1/k)*vecdict[k] for k in vecdict.keys()]    
    
    '''
    >>> v1 = Vec({1,2,3}, {2: 9})
    >>> v2 = Vec({1,2,4}, {1: 1, 2: 2, 4: 8})
    >>> scale_vecs({3: v1, 5: v2}) == [Vec({1,2,3},{2: 3.0}), Vec({1,2,4},{1: 0.2, 2: 0.4, 4: 1.6})]
    True
    '''
    
def dec2bin(dec,dim):
    l = [0]*dim
    #print('dec = %d and dim = %d'%(dec,dim))
    binary = bin(dec)[2:]
    if(len(binary) < dim):
        binary = '0'*(dim-len(binary))+binary
        #print(binary)
    #print('len of binary number is %d'%len(binary))
    for i in range(len(binary)):
        #print(binary[i])
        if binary[i] == '1':
            l[i] = 1
    #print(l)
    l.reverse()
    return l
## Problem 3
def GF2_span(D, L):
    
    s = []
    for i in range(2*len(L)):
        coff = dec2bin(i,len(L))
        #print('len of coff is %d'%len(coff))
#        for index in range(len(coff)):
#            print('coff[%d] = %d'%(index,coff[index]))
#            #print(L[index])
#            v = coff[index]*L[index]
#            print(v)
        l = [coff[index]*L[index] for index in range(len(coff))]
        #print('l = '+l)
        s.append(vec_sum(l,D))        
        #print(s)
    return s
    
   # return [Vec(D,{l*dec2bin(x,len(L)) for x in range((2**len(L))) for l in L]
    '''
    >>> from GF2 import one
    >>> D = {'a', 'b', 'c'}
    >>> L = [Vec(D, {'a': one, 'c': one}), Vec(D, {'b': one})]
    >>> len(GF2_span(D, L))
    4
    >>> Vec(D, {}) in GF2_span(D, L)
    True
    >>> Vec(D, {'b': one}) in GF2_span(D, L)
    True
    >>> Vec(D, {'a':one, 'c':one}) in GF2_span(D, L)
    True
    >>> Vec(D, {x:one for x in D}) in GF2_span(D, L)
    True
    '''
    




## Problem 4
# Answer with a boolean, please.

is_it_a_vector_space_1 = True
is_it_a_vector_space_2 = False



## Problem 5
is_it_a_vector_space_3 = True
is_it_a_vector_space_4 = False


## Problem 6

is_it_a_vector_space_5 = True
is_it_a_vector_space_6 = False
